package javavis.jip3d.functions;

import javavis.base.Function3DGroup;
import javavis.base.JIPException;
import javavis.base.ParamType;
import javavis.jip3d.gui.Function3D;
import javavis.jip3d.gui.FunctionParam;
import javavis.jip3d.gui.ScreenData;
import javavis.jip3d.gui.ScreenOptions;
import javavis.jip3d.gui.dataobjects.PointSet3D;
import javavis.jip3d.gui.dataobjects.SR4000Set3D;
import javavis.jip3d.gui.dataobjects.Trajectory;

public class FSR4KProcess extends Function3D {

	public FSR4KProcess() {
		name = "FSR4kProcess";
		this.allowed_input = ScreenOptions.tTRAJ3D;
		this.group = Function3DGroup.Others;

		//minimum distance
		FunctionParam p1 = new FunctionParam("distance", ParamType.FLOAT);
		p1.setValue(1.0);
		//minimum confidence
		FunctionParam p2 = new FunctionParam("confidence", ParamType.INT);
		p2.setValue(240);
		//minimum intensity
		FunctionParam p3 = new FunctionParam("intensity", ParamType.INT);
		p3.setValue(25);
		
		FunctionParam p4 = new FunctionParam("Output", ParamType.DIR);
		
		addParam(p1);
		addParam(p2);
		addParam(p3);
		addParam(p4);
	}

	@Override
	public void proccessData(ScreenData scrData) throws JIPException {
		int cont, total;
		String file_name, path;
		SR4000Set3D sr4kset;
		PointSet3D ptset;
		
		//get input parameters
		double minDist = this.paramValueReal("distance");
		int minConf = this.paramValueInt("confidence");
		int minInt = this.paramValueInt("intensity");
		String ruta_puntos = this.paramValueString("Output");
		
		//filtering function
		FSR4kFilter fsrf = new FSR4kFilter();
		fsrf.setParamValue("distance", minDist);
		fsrf.setParamValue("confidence", minConf);
		fsrf.setParamValue("intensity", minInt);
		
		Trajectory traj = (Trajectory)scrData;
		total = traj.files.size();
		path = traj.path;
		for(cont=0;cont<total;cont++)
		{
			file_name = traj.files.get(cont);
			sr4kset = new SR4000Set3D(new ScreenOptions());
			sr4kset.name = file_name;
			sr4kset.readData(file_name, path);
			
			fsrf.proccessData(sr4kset);
			ptset = (PointSet3D)fsrf.result_list.get(0);
			ptset.writeData(file_name, ruta_puntos);
		}

	}

}
